package javasy.newpackage;
public class NewClass_Nbl {//分离出运算式中的括号与数字，不包括运算符
    private static int count=0;
    private  int step=-1;
    public String getNumber(String str){
        step=-1;
        String info="";
        if(count>=str.length())
            return "0";
        if(count<str.length()&&(str.charAt(count)=='('||str.charAt(count)==')')){
           return ""+str.charAt(count++);
        }
        while(count<str.length()&&str.charAt(count)>='0'&&str.charAt(count)<='9'){
                info+=str.charAt(count);
                count++;
                if(count<str.length()&&str.charAt(count)=='.'){
                    info+=".";
                    count++;
                }
                step=0;
            }
        if(count<str.length()&&count!=str.length()-1&&str.charAt(count)!='('&&str.charAt(count)!=')')
           count++;
        else if(count==str.length()-1&&step==-1){
            if(str.charAt(count)=='+'||str.charAt(count)=='-'||str.charAt(count)=='*'||str.charAt(count)=='/'){
               count++;
               throw new IllegalArgumentException("该运算式不完整");
         }
        }
        if(step==0)
          return info;
        else if(count<str.length()&&str.charAt(count)=='('||str.charAt(count)==')')
            return ""+str.charAt(count++);
        else{
            while(count<str.length()&&str.charAt(count)>='0'&&str.charAt(count)<='9'){
                info+=str.charAt(count);
                count++;
            }
            return info; 
        }
    }
}
